<?php

function __autoload($class_name)
{
	if (is_int(strpos($class_name,'Xbb_Tags_')))
	{
		$class_name = str_replace('Xbb_Tags_', '', $class_name);
		include(BASE_DIR.'/lib/bbcode/tags/'.$class_name.'.php');
		return;
	}
	$class_name = strtolower($class_name);
	$paths = explode('_', $class_name);
	if (sizeof($paths) > 1)
	{
	    if ($paths[0] == 'controller')
	    {
            $sFilePath = BASE_DIR.'/'.implode('/', $paths).'.php';

	    }
		elseif ($paths[0] == 'model' || $paths[0] == 'service')
		{
		    $sFilePath = BASE_DIR.'/'.$paths[0].'/'.$paths[1].'.php';
		}
		else
		{
		    $sFilePath = BASE_DIR.'/lib/'.$paths[0].'/'.$paths[1].'.php';
		}
	}
	else
	{
	    $sFilePath = BASE_DIR.'/lib/'.$paths[0].'.php';
	}
	
	if (file_exists($sFilePath))
	{
	    require_once($sFilePath);
	}
}